
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Polygon;
import javax.swing.BorderFactory;
import javax.swing.JPanel;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author alrz
 */
public class Figura extends JPanel
{
    private int up;
    private int down;
    private int left;
    private int right;
    private boolean pressed;
    
    public Figura()
    {
        super();
        this.pressed = false;
    }

    public Figura(int up, int down, int left, int right)
    {
        super();
        this.up = up;
        this.down = down;
        this.left = left;
        this.right = right;
        this.pressed = false;
    }

    public int getDown() {
        return down;
    }

    public void setDown(int down) {
        this.down = down;
    }

    public boolean isPressed() {
        return pressed;
    }

    public void setPressed(boolean isPressed) {
        this.pressed = isPressed;
    }

    public int getLeft() {
        return left;
    }

    public void setLeft(int left) {
        this.left = left;
    }

    public int getRight() {
        return right;
    }

    public void setRight(int right) {
        this.right = right;
    }

    public int getUp() {
        return up;
    }

    public void setUp(int up) {
        this.up = up;
    }
    
    @Override
    public void paint(Graphics g)
    {
        super.paintComponent(g);
        Polygon p = new Polygon();
        this.setBorder(BorderFactory.createLineBorder(Color.BLACK));
        //UP
        p.addPoint(0, 0);
        p.addPoint(this.getWidth(),0);
        p.addPoint(this.getWidth()/2, this.getHeight()/2);
        g.setColor(this.verColor(this.right));
        g.fillPolygon(p);
        g.setColor(Color.red);
        g.drawString(""+this.up,this.getWidth()/2 , this.getHeight()/4);
        //LEFT
        p.reset();
        p.addPoint(0, 0);
        p.addPoint(this.getWidth()/2, this.getHeight()/2);
        p.addPoint(0,this.getHeight());
        g.setColor(this.verColor(this.left));
        g.fillPolygon(p);
        g.setColor(Color.red);
        g.drawString(""+this.left,this.getWidth()/4 , this.getHeight()/2);
        //DOWN
        p.reset();
        p.addPoint(0,this.getHeight());
        p.addPoint(this.getWidth(),this.getHeight());
        p.addPoint(this.getWidth()/2, this.getHeight()/2);
        g.setColor(this.verColor(this.down));
        g.fillPolygon(p);
        g.setColor(Color.red);
        g.drawString(""+this.down,this.getWidth()/2 , 3*this.getHeight()/4);
        //RIGHT
        p.reset();
        p.addPoint(this.getWidth(),this.getHeight());
        p.addPoint(this.getWidth(),0);
        p.addPoint(this.getWidth()/2, this.getHeight()/2);
        g.setColor(this.verColor(this.right));
        g.fillPolygon(p);
        g.setColor(Color.red);
        g.drawString(""+this.down,3*this.getWidth()/4 , this.getHeight()/2);
        
        g.setColor(Color.BLACK);
        g.drawLine(0, 0, this.getWidth(), this.getHeight());
        g.drawLine(this.getWidth(),0,0,this.getHeight());
    }
    
    public Color verColor(int value)
    {
        if(value == 1)
        {
            
        }
        if(value == 2)
        {
            return Color.RED;
        }
        if(value == 3)
        {
            return Color.ORANGE;
        }
        if(value == 4)
        {
            return Color.YELLOW;
        }
        if(value == 5)
        {
            return Color.GREEN;
        }
        if(value == 6)
        {
            return Color.BLUE;
        }
        if(value == 7)
        {
            return Color.MAGENTA;
        }
        if(value == 8)
        {
            return Color.GRAY;
        }
        if(value == 9)
        {
            return Color.WHITE;
        }
        return Color.BLACK;
    }
}
